package org.saxion.saktiehuis.service;

import java.util.List;

import org.saxion.saktiehuis.dao.GenericDao;
import org.saxion.saktiehuis.model.ProductCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class ProductCategoryService {
	@Autowired
	private GenericDao<ProductCategory, Long> categoryDao;

	public ProductCategory getProductCategoryByName(String name) {
		List<ProductCategory> list = categoryDao
				.findAllByProperty("name", name);
		return (!list.isEmpty()) ? list.get(0) : null;
	}

	public List<ProductCategory> getProductCategories() {
		List<ProductCategory> list = categoryDao.findAll();
		return list;
	}

	public ProductCategory getProductCategoryById(Long id) {
		return categoryDao.findById(id);
	}
}
